package client.gui;

import java.awt.Button;
import java.awt.GridLayout;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

/**
 * The Class ErrorMessageGui
 *  - used to create a popup window
 *   for displaying error messages.
 */
public class ErrorMessageGui extends JPanel{
	
	private static final long serialVersionUID = -5922463513364719998L;
	
	/** The error message. */
	String message;
	
	/** The popup frame. */
	JFrame frame;
	
	/**
	 * Instantiates a new error message gui.
	 *
	 * @param message the error message
	 */
	public ErrorMessageGui(String message){
		this.message = message;
		run();
	}
	
	/**
	 * Run - builds the gui.
	 */
	public void run(){
		frame = new JFrame("Error");
		frame.setVisible(true);
		JLabel error = new JLabel("  " + message, JLabel.CENTER);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setLayout(new GridLayout(2,1));
		frame.setSize(450, 75);
		error.setVisible(true);
		Button ok = new Button(("OK"));
		ok.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseReleased(MouseEvent e) {
				System.exit(0);
			}
		});
		this.add(error);
		this.add(ok);
		frame.add(this);
	}
}
